Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding "cookie id" to metrics event #26697

Merged
merged 12 commits into from
Sep 13, 2024
Merged

Conversation

NiranjanaBinoy
Copy link
Contributor

@NiranjanaBinoy NiranjanaBinoy commented Aug 27, 2024

Description

The PR sets up a stream communication with the label 'metamask-cookie-handler'. The data sent from the page will be intercepted at the content-script and forwarded to the extension. The 'ga_client_id' sent from the page is saved as marketingCampaignCookieId in the metaMetricsController state and fetched when building the context for each event.

Open in GitHub Codespaces

Related issues

Part of https://github.com/MetaMask/MetaMask-planning/issues/2916

Manual testing steps

To test the stream, Open https://metamask.io/ , and write a request in dev tools console with the following window.postMessage would do. This should update the metametricsController state with marketingCampaignCookieId. Logging the payload in _track() in MetaMetricsController will show that the marketingCampaignCookieId is added to the context.

window.postMessage(
      {
        target: 'metamask-contentscript', 
        data: {
          name: 'metamask-cookie-handler', 
          data: {
            jsonrpc: '2.0',
            method: 'getCookieFromMarketingPage',
            params: [{ ga_client_id: 12345, origin: 'https://metamask.io' }],
            id: '1234',
            origin: 'https://metamask.io',
          },
        },
      },
      'https://metamask.io',
    );

Test the track event sending after this has this id in its context as marketingCampaignCookieId.

Screenshots/Recordings

After

Loading a website in the from the white list:

whitelist-website.mov

Initially loading a website not from the whitelist and then loading a website from whitelist to compare the context data:

website_not_in_whitelist.mov

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@NiranjanaBinoy NiranjanaBinoy requested a review from a team as a code owner August 27, 2024 20:39
@NiranjanaBinoy NiranjanaBinoy self-assigned this Aug 27, 2024
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@NiranjanaBinoy NiranjanaBinoy changed the title Adding "cookie id" to metrics event feat: Adding "cookie id" to metrics event Aug 27, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [09186f5]
Page Load Metrics (1560 ± 42 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1387169615668541
domContentLoaded1378168815458842
load1386169615608842
domInteractive21532794
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.57 KiB (0.07%)
  • ui: 0 Bytes (0.00%)
  • common: 29 Bytes (0.00%)

Copy link

codecov bot commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 12.69841% with 110 lines in your changes missing coverage. Please review.

Project coverage is 69.90%. Comparing base (b01f0c9) to head (0677ee6).

Files with missing lines Patch % Lines
app/scripts/streams/cookie-handler-stream.ts 0.00% 58 Missing ⚠️
app/scripts/contentscript.js 0.00% 28 Missing ⚠️
app/scripts/metamask-controller.js 0.00% 12 Missing ⚠️
app/scripts/background.js 0.00% 6 Missing ⚠️
app/scripts/constants/marketing-site-whitelist.ts 0.00% 4 Missing ⚠️
app/scripts/streams/shared.ts 0.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #26697      +/-   ##
===========================================
- Coverage    70.04%   69.90%   -0.13%     
===========================================
  Files         1435     1439       +4     
  Lines        49920    50044     +124     
  Branches     13980    13995      +15     
===========================================
+ Hits         34963    34983      +20     
- Misses       14957    15061     +104     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@legobeat legobeat requested a review from a team August 28, 2024 21:13
@NiranjanaBinoy NiranjanaBinoy force-pushed the feature/2916-cookie branch 3 times, most recently from ee1b204 to df8983a Compare September 3, 2024 15:04
@metamaskbot
Copy link
Collaborator

Builds ready [df8983a]
Page Load Metrics (1762 ± 102 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint25521291587453218
domContentLoaded15352355174119694
load154023941762212102
domInteractive13103372211
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.95 KiB (0.09%)
  • ui: 0 Bytes (0.00%)
  • common: 29 Bytes (0.00%)

@metamaskbot
Copy link
Collaborator

Builds ready [32f8155]
Page Load Metrics (2928 ± 291 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint281355419861263606
domContentLoaded171642362899602289
load172942632928607291
domInteractive14281785627
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.95 KiB (0.09%)
  • ui: 0 Bytes (0.00%)
  • common: 29 Bytes (0.00%)

vthomas13
vthomas13 previously approved these changes Sep 9, 2024
@vthomas13 vthomas13 self-requested a review September 9, 2024 20:07
@DDDDDanica
Copy link
Contributor

DDDDDanica commented Sep 10, 2024

Hey @NiranjanaBinoy I must be missing the implementation of this - we need to modify the body of event sent to segment and add context to it:

Additional technical details are that the method buildContext is where I believe we would add in our ga_client_id key / value pair. This would then pass this along with all track and identify calls.

Can you show me where is it? thank you !

Copy link
Contributor

@DDDDDanica DDDDDanica left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@NiranjanaBinoy Thanks for putting everything together !

Can you add the description in this ticket for manual tests as

  • test the track event sending after this has this id

It is also valuable to add a screen recording of if works for

  • marketing whitelist site
  • site doesn't have this id passing

Thanks a lot !

@NiranjanaBinoy NiranjanaBinoy force-pushed the feature/2916-cookie branch 2 times, most recently from 7e1ce7f to 978f71b Compare September 12, 2024 14:43
@metamaskbot
Copy link
Collaborator

Builds ready [978f71b]
Page Load Metrics (1943 ± 107 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint47324301858383184
domContentLoaded166024091923213102
load166924321943222107
domInteractive127637157
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.88 KiB (0.08%)
  • ui: 0 Bytes (0.00%)
  • common: 29 Bytes (0.00%)

Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally looks good. I have left some questions and suggestions

app/scripts/controllers/metametrics.js Show resolved Hide resolved
@@ -5114,6 +5119,42 @@ export default class MetamaskController extends EventEmitter {
);
}

setUpCookieHandlerCommunication({ connectionStream }) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should create a github issue for adding unit tests for this method and for setupPhishingCommunication

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. #27119

app/scripts/contentscript.js Show resolved Hide resolved
@@ -0,0 +1,193 @@
import browser from 'webextension-polyfill';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file looks good

app/scripts/background.js Show resolved Hide resolved
Copy link

sonarcloud bot commented Sep 13, 2024

@metamaskbot
Copy link
Collaborator

Builds ready [0677ee6]
Page Load Metrics (1686 ± 66 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint22020111478533256
domContentLoaded14941927166211857
load15022022168613866
domInteractive168036168
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 2.88 KiB (0.08%)
  • ui: 0 Bytes (0.00%)
  • common: 29 Bytes (0.00%)

@NiranjanaBinoy
Copy link
Contributor Author

Hey @NiranjanaBinoy I must be missing the implementation of this - we need to modify the body of event sent to segment and add context to it:

Additional technical details are that the method buildContext is where I believe we would add in our ga_client_id key / value pair. This would then pass this along with all track and identify calls.

Can you show me where is it? thank you !

We are saving the cookieId to the state of the MetaMetrics controller as marketingCampaignCookieId and in _buildContext we are using the value in the variable to populate marketingCampaignCookieId property of the context here

@DDDDDanica
Copy link
Contributor

LGTM 🔥

@NiranjanaBinoy NiranjanaBinoy merged commit ca6fd53 into develop Sep 13, 2024
81 checks passed
@NiranjanaBinoy NiranjanaBinoy deleted the feature/2916-cookie branch September 13, 2024 19:34
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2024
@metamaskbot metamaskbot added release-12.6.0 Issue or pull request that will be included in release 12.6.0 release-12.3.0 Issue or pull request that will be included in release 12.3.0 and removed release-12.6.0 Issue or pull request that will be included in release 12.6.0 labels Sep 13, 2024
@metamaskbot
Copy link
Collaborator

Missing release label release-12.3.0 on PR. Adding release label release-12.3.0 on PR and removing other release labels(release-12.6.0), as PR was cherry-picked in branch 12.3.0.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-privacy release-12.3.0 Issue or pull request that will be included in release 12.3.0 team-extension-platform
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants